package fr.vod.threads;

import fr.vod.gauss.File.File;
import fr.vod.net.Sender;
import fr.vod.util.LogHelper;

/**
 * 
 * @author drazanakoto
 * 
 */
public class DataSender extends Thread {

	// / tag des logs
	private final static String logTag = DataSender.class.getName();

	private boolean stop = false;
	private Sender s;
	private File pi;

	/**
	 * 
	 * @param pi
	 * @param s
	 */
	public DataSender(File pi, Sender s) {
		this.pi = pi;
		this.s = s;
	}

	public void run() {
		LogHelper.information(logTag, "sending data");
		byte[] tab;

		while (!stop) {
			try {
				tab = pi.create();
				s.send(tab);
				Thread.sleep(5);
			} catch (Exception e) {
				LogHelper.erreur("Error", "Send block " + e.getMessage());
			}
		}
	}

	/**
	 * 
	 */
	public void end() {
		stop = true;
	}

	public int read() throws Exception {
		return pi.readNextBlock();
	}
}
